<?php
use app\assets\AppAsset;
use yii\widgets\LinkPager;
$baseUrl = Yii::$app->request->baseUrl;
AppAsset::addCss($this, $baseUrl . "/css/home.css");
AppAsset::addCss($this, $baseUrl . "/css/kkpager_orange.css");
AppAsset::addScript($this, $baseUrl . "/js/kkpager.min.js");
?>
<div class="head">
    <div class="title">首页</div>
    <div style="float: right;position: relative;top: -30px;">
        <button type="button" class="my-btn"
                data-toggle="button" style="margin-right: 15px"> 上传图片
        </button>
        <img src="../../img/head.jpeg" style="width: 40px;height: auto;margin-right: 15px">
        <span style="font-size: 16px;margin-right: 40px">退出</span>
    </div>
</div>
<div class="thin">

</div>

<div class="poster-content">

</div>

<div style="width:800px;margin:0 auto;">
    <div id="kkpager" class="kkpager">
    </div>
</div>
<script type="text/javascript">
    function getParameter(name) {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }

    //init
    $(function(){
        var totalPage = <?= $pageSize ?>;
        var totalRecords = <?= $total ?>;
        var pageNo = getParameter('pno');
        if(!pageNo){
            pageNo = 1;
        }
        console.log('pageNo',pageNo);
        $.ajax({
            url:'get-poster',
            data:{'pageNum':2},
            dataType:'json',
            success:function(data){
                console.log('hahah',data);
                for(var i= 0,l=data.length;i<l;i++){
                    console.log(data[i].poster_img);
                    $(".poster-content").append(
                        "<ul> " +
                        "<li> " +
                        "<div class=\"poster-handle\"> " +
                        "<div>下移1</div> " +
                        "<div>删除</div> " +
                        "<div>显示<input type=\"checkbox\"></div> " +
                        "</div> " +
                        "<div class=\"poster-body\"> " +
                        "<div class=\"poster-number\">海报(一):</div> " +
                        "<div class=\"poster-img\"><img src=\""+data[i].poster_img+"\"></div>" +
                        "</div> " +
                        "</li> "+
                        "</ul>")
                }
            }
        });

        //生成分页
        //有些参数是可选的，比如lang，若不传有默认值
        kkpager.generPageHtml({
            pno : pageNo,//当前页数
            //总页码
            total : totalPage,
            //总数据条数
            totalRecords : totalRecords,//总数据条数
            mode : 'click',//默认值是link，可选link或者click
            click : function(n){
                // do something
                //手动选中按钮
                console.log('nnn',n);
                $(".poster-content").html("");
                $.ajax({
                    url:'get-poster',
                    data:{'pageNum':n},
                    dataType:'json',
                    success:function(data){
                        console.log('hahah',data);
                        for(var i= 0,l=data.length;i<l;i++){
                            console.log(data[i].poster_img);
                            $(".poster-content").append(
                                "<ul> " +
                                "<li> " +
                                "<div class=\"poster-handle\"> " +
                                "<div>下移1</div> " +
                                "<div>删除</div> " +
                                "<div>显示<input type=\"checkbox\"></div> " +
                                "</div> " +
                                "<div class=\"poster-body\"> " +
                                "<div class=\"poster-number\">海报(一):</div> " +
                                "<div class=\"poster-img\"><img src=\""+data[i].poster_img+"\"></div>" +
                                "</div> " +
                                "</li> "+
                                "</ul>")
                        }
                    }
                });



                this.selectPage(n);

                //return false;
            },

             lang: {
             firstPageText			: '首页',
             firstPageTipText		: '首页',
             lastPageText			: '尾页',
             lastPageTipText			: '尾页',
             prePageText				: '上一页',
             prePageTipText			: '上一页',
             nextPageText			: '下一页',
             nextPageTipText			: '下一页',
             totalPageBeforeText		: '共',
             totalPageAfterText		: '页',
             currPageBeforeText		: '当前第',
             currPageAfterText		: '页',
             totalInfoSplitStr		: '/',
             totalRecordsBeforeText	: '共',
             totalRecordsAfterText	: '条数据',
             gopageBeforeText		: '&nbsp;转到',
             gopageButtonOkText		: '确定',
             gopageAfterText			: '页',
             buttonTipBeforeText		: '第',
             buttonTipAfterText		: '页'
             }
        });
    });
</script>

